﻿/**  版本信息模板在安装目录下，可自行修改。
* NewStaffLessonsCheck.cs
*
* 功 能： N/A
* 类 名： NewStaffLessonsCheck
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2015/4/11 14:29:36   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Catering_DBOpertion;//Please add references
namespace Catering_Operation
{
	/// <summary>
	/// 数据访问类:NewStaffLessonsCheck
	/// </summary>
	public partial class NewStaffLessonsCheck
	{
		public NewStaffLessonsCheck()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("LessonID", "T_NewStaffLessonsCheck"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int LessonID,int UserID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_NewStaffLessonsCheck");
			strSql.Append(" where LessonID=@LessonID and UserID=@UserID ");
			SqlParameter[] parameters = {
					new SqlParameter("@LessonID", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4)			};
			parameters[0].Value = LessonID;
			parameters[1].Value = UserID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Catering_Model.NewStaffLessonsCheck model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_NewStaffLessonsCheck(");
			strSql.Append("LessonID,UserID,IsRegister,CheckStatus,CheckUserID,CheckTime,Remark,AddUserID,AddTime)");
			strSql.Append(" values (");
			strSql.Append("@LessonID,@UserID,@IsRegister,@CheckStatus,@CheckUserID,@CheckTime,@Remark,@AddUserID,@AddTime)");
			SqlParameter[] parameters = {
					new SqlParameter("@LessonID", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4),
					new SqlParameter("@IsRegister", SqlDbType.Bit,1),
					new SqlParameter("@CheckStatus", SqlDbType.VarChar,50),
					new SqlParameter("@CheckUserID", SqlDbType.Int,4),
					new SqlParameter("@CheckTime", SqlDbType.DateTime),
					new SqlParameter("@Remark", SqlDbType.Text),
					new SqlParameter("@AddUserID", SqlDbType.Int,4),
					new SqlParameter("@AddTime", SqlDbType.DateTime)};
			parameters[0].Value = model.LessonID;
			parameters[1].Value = model.UserID;
			parameters[2].Value = model.IsRegister;
			parameters[3].Value = model.CheckStatus;
			parameters[4].Value = model.CheckUserID;
			parameters[5].Value = model.CheckTime;
			parameters[6].Value = model.Remark;
			parameters[7].Value = model.AddUserID;
			parameters[8].Value = model.AddTime;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Catering_Model.NewStaffLessonsCheck model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_NewStaffLessonsCheck set ");
			strSql.Append("IsRegister=@IsRegister,");
			strSql.Append("CheckStatus=@CheckStatus,");
			strSql.Append("CheckUserID=@CheckUserID,");
			strSql.Append("CheckTime=@CheckTime,");
			strSql.Append("Remark=@Remark,");
			strSql.Append("AddUserID=@AddUserID,");
			strSql.Append("AddTime=@AddTime");
			strSql.Append(" where LessonID=@LessonID and UserID=@UserID ");
			SqlParameter[] parameters = {
					new SqlParameter("@IsRegister", SqlDbType.Bit,1),
					new SqlParameter("@CheckStatus", SqlDbType.VarChar,50),
					new SqlParameter("@CheckUserID", SqlDbType.Int,4),
					new SqlParameter("@CheckTime", SqlDbType.DateTime),
					new SqlParameter("@Remark", SqlDbType.Text),
					new SqlParameter("@AddUserID", SqlDbType.Int,4),
					new SqlParameter("@AddTime", SqlDbType.DateTime),
					new SqlParameter("@LessonID", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4)};
			parameters[0].Value = model.IsRegister;
			parameters[1].Value = model.CheckStatus;
			parameters[2].Value = model.CheckUserID;
			parameters[3].Value = model.CheckTime;
			parameters[4].Value = model.Remark;
			parameters[5].Value = model.AddUserID;
			parameters[6].Value = model.AddTime;
			parameters[7].Value = model.LessonID;
			parameters[8].Value = model.UserID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int LessonID,int UserID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_NewStaffLessonsCheck ");
			strSql.Append(" where LessonID=@LessonID and UserID=@UserID ");
			SqlParameter[] parameters = {
					new SqlParameter("@LessonID", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4)			};
			parameters[0].Value = LessonID;
			parameters[1].Value = UserID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Catering_Model.NewStaffLessonsCheck GetModel(int LessonID,int UserID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 LessonID,UserID,IsRegister,CheckStatus,CheckUserID,CheckTime,Remark,AddUserID,AddTime from T_NewStaffLessonsCheck ");
			strSql.Append(" where LessonID=@LessonID and UserID=@UserID ");
			SqlParameter[] parameters = {
					new SqlParameter("@LessonID", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4)			};
			parameters[0].Value = LessonID;
			parameters[1].Value = UserID;

			Catering_Model.NewStaffLessonsCheck model=new Catering_Model.NewStaffLessonsCheck();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Catering_Model.NewStaffLessonsCheck DataRowToModel(DataRow row)
		{
			Catering_Model.NewStaffLessonsCheck model=new Catering_Model.NewStaffLessonsCheck();
			if (row != null)
			{
				if(row["LessonID"]!=null && row["LessonID"].ToString()!="")
				{
					model.LessonID=int.Parse(row["LessonID"].ToString());
				}
				if(row["UserID"]!=null && row["UserID"].ToString()!="")
				{
					model.UserID=int.Parse(row["UserID"].ToString());
				}
				if(row["IsRegister"]!=null && row["IsRegister"].ToString()!="")
				{
					if((row["IsRegister"].ToString()=="1")||(row["IsRegister"].ToString().ToLower()=="true"))
					{
						model.IsRegister=true;
					}
					else
					{
						model.IsRegister=false;
					}
				}
				if(row["CheckStatus"]!=null)
				{
					model.CheckStatus=row["CheckStatus"].ToString();
				}
				if(row["CheckUserID"]!=null && row["CheckUserID"].ToString()!="")
				{
					model.CheckUserID=int.Parse(row["CheckUserID"].ToString());
				}
				if(row["CheckTime"]!=null && row["CheckTime"].ToString()!="")
				{
					model.CheckTime=DateTime.Parse(row["CheckTime"].ToString());
				}
				if(row["Remark"]!=null)
				{
					model.Remark=row["Remark"].ToString();
				}
				if(row["AddUserID"]!=null && row["AddUserID"].ToString()!="")
				{
					model.AddUserID=int.Parse(row["AddUserID"].ToString());
				}
				if(row["AddTime"]!=null && row["AddTime"].ToString()!="")
				{
					model.AddTime=DateTime.Parse(row["AddTime"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select LessonID,UserID,IsRegister,CheckStatus,CheckUserID,CheckTime,Remark,AddUserID,AddTime ");
			strSql.Append(" FROM T_NewStaffLessonsCheck ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" LessonID,UserID,IsRegister,CheckStatus,CheckUserID,CheckTime,Remark,AddUserID,AddTime ");
			strSql.Append(" FROM T_NewStaffLessonsCheck ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_NewStaffLessonsCheck ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.UserID desc");
			}
			strSql.Append(")AS Row, T.*  from T_NewStaffLessonsCheck T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "T_NewStaffLessonsCheck";
			parameters[1].Value = "UserID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int LessonID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_NewStaffLessonsCheck ");
            strSql.Append(" where LessonID=@LessonID ");
            SqlParameter[] parameters = {
					new SqlParameter("@LessonID", SqlDbType.Int,4)};
            parameters[0].Value = LessonID;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

		#endregion  ExtensionMethod
	}
}

